<script setup >
import { OpenChat, CloseChat } from '../../../wailsjs/go/main/App'
import {ref} from "vue";
import { message } from 'ant-design-vue'

const form = ref({
  call: ""
})

// 保存配置
const open = async () => {
  try {
    await OpenChat(form.value.call)
    message.success('开启机器人成功')
  } catch (err) {
    message.error('开启机器人失败: ' + err.message)
  }
}
// 保存配置
const stop = async () => {
  try {
    await CloseChat()
    message.success('关闭机器人成功')
  } catch (err) {
    message.error('关闭机器人失败: ' + err.message)
  }
}
</script>

<template>
  <div class="container">
    <h3 style="width: 100%; text-align: center">微信机器人</h3>

    <a-form
        :model="form"
        name="basic"
        :label-col="{ span: 3 }"
        :wrapper-col="{ span: 16 }"
        autocomplete="off"
    >
      <a-form-item
          label="监听对象"
          name="call"
          :rules="[{ required: true, message: 'Please input your username!' }]"
      >
        <a-input v-model:value="form.call" />
      </a-form-item>
      <a-form-item >
        <a-button type="primary" @click="open">开启</a-button>
        <a-button style="margin-left: 20px" @click="stop">关闭</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<style scoped>

</style>